//
//  JQFYCheckTikectView.m
//  JQFY
//
//  Created by 代辉 on 2017/9/27.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYCheckTikectView.h"

@interface JQFYCheckTikectView ()

@property (nonatomic,strong) UIImageView *QRCode;
@property (nonatomic,weak) UIButton *reusltInformation;

@end
@implementation JQFYCheckTikectView {
    UIActivityIndicatorView *_indicator;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI
{
    UIImageView *x = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"X"]];
    x.userInteractionEnabled = YES;
    UITapGestureRecognizer *dissMiss = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resultAction)];
    [x addGestureRecognizer:dissMiss];
    [self addSubview:x];
    [x mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(64 *SCAL);
        make.centerX.equalTo(self);
    }];
    
    
    [self addSubview:self.QRCode];
    [self.QRCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(x.mas_bottom).offset(23 *SCAL);
        make.centerX.equalTo(self);
    }];
    
    _indicator = [UIActivityIndicatorView new];
    [self addSubview:_indicator];
    [_indicator mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.QRCode);
    }];
    [_indicator startAnimating];
    
    UIImageView *qrCodeBorder = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"qr_code_border"]];
    [self addSubview:qrCodeBorder];
    [qrCodeBorder mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.QRCode);
    }];
    
    UIImageView *information = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"information"]];
    [self addSubview:information];
    [information mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.QRCode.mas_bottom).offset(40 *SCAL);
        make.left.equalTo(self.QRCode);
    }];
    
    UIButton *reusltInformation = [UIButton buttonWithType:UIButtonTypeCustom];
    [reusltInformation setBackgroundImage:[UIImage imageNamed:@"圆角矩形3"] forState:UIControlStateNormal];
#warning 需要验证 有没有用过然后修改title
    [reusltInformation setImage:[UIImage imageNamed:@"请让工作人员扫码"] forState:UIControlStateNormal];
    self.reusltInformation = reusltInformation;
    [self addSubview:reusltInformation];
    [reusltInformation mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.QRCode);
        make.bottom.equalTo(self).offset(-45 *SCAL);
    }];
    [reusltInformation addTarget:self action:@selector(resultAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)resultAction
{
    [[NSNotificationCenter defaultCenter] postNotificationName:AleartCheckTikectNoification object:@(2)];
}

//二维码状态
-(void)setStatus:(NSInteger)status
{
    _status = status;
    [self.reusltInformation setImage:[UIImage imageNamed:@"你的二维码已使用"] forState:UIControlStateNormal];
}

// 二维码
- (void)setOrderID:(NSString *)orderID
{
    _orderID = orderID;
    [_indicator stopAnimating];
    [self.QRCode sd_setImageWithURL:[NSURL URLWithString:orderID]];
}
/**
 二维码
 */
- (UIImageView *)QRCode
{
    if (_QRCode == nil) {
        _QRCode = [[UIImageView alloc] init];
        _QRCode.image = [UIImage imageNamed:@"er_code"];
        
    }
    return _QRCode;
}
@end
